<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDealRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('deal_records', function (Blueprint $table) {
            $table->id();
            $table->integer('store_id')->unsigned()->default(0)->comment('店铺id');
            $table->integer('user_id')->unsigned()->comment('用户id');
            $table->integer('amount')->unsigned()->default(0)->comment('涉及金额单位（分）');
            $table->string('type', 50)->default('')->comment('资金出入类型：in-入，out-出');
            $table->tinyInteger('status')->default(0)->comment('资金操作状态:0-未生效;1-已生效;2-待分配;3-已分配;4-冻结;0,1针对out的资金,2,3针对in的资金;0,2代表未更新到对应用户余额,1,3表示已经更新到对应用户余额;');
            $table->string('reason')->default('')->comment('资金出入理由');
            $table->tinyInteger('deal_type')->default(0)->comment('交易类型: 1微信充值, 2易宝充值, 3后台充值, 4提现, 5拒绝提现返还余额, 6会员支付订单, 7分享奖金 N级内, 8分享奖金 N级外, 9公司所得, 10军功章折算余额, 11后台扣除款项, 12注册获取积分, 13推荐获取积分, 14会员订货本人获取积分, 15公司发放积分, 16会员订单使用积分, 17会员订货获取军功章, 18军功章N级内, 19军功章N级外');
            $table->integer('last_balance')->unsigned()->default(0)->comment('变更前用户余额');
            $table->integer('new_balance')->unsigned()->default(0)->comment('变更后用户余额');
            $table->integer('deal_item_id')->unsigned()->default(0)->comment('交易相关活动ID,参考deal_type.譬如会员购买,就是订单ID,此ID 必需考虑 不能有不同订单但是相同ID的出现');
            $table->tinyInteger('order_type')->default(1)->comment('充值1,提现2,会员订单3,后台发放4,军功章转化余额5');
            $table->tinyInteger('jm_type')->default(1)->comment('默认为1,余额,2 为积分,3为军功章');
            $table->tinyInteger('grade')->default(0)->comment('产生交易记录时用户的身份');
            $table->string('mark')->default('')->comment('交易记录备注 后台标记, 或系统标注留存, 方便理解数据含义');
            $table->timestamps();
        });

        DB::statement("ALTER TABLE `deal_records` comment '交易记录表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('deal_records');
    }
}
